<template>
	<view>
		
	</view>
</template>

<script>
	import amap from "@/static/amap-wx.130.js"
		export default {
			name:"posution-info",
			data() {
				return {
					amapPlugin: null,
					gaodekey: '1ff082e63b6d8f21ab6c949e51e54abf', //高德key,此处的key需要去高德平台申请获取，此key是假的！！！
					address: "", // 已经获取到的位置
				}
			},
			created() {
				this.amapPlugin = new amap.AMapWX({
					key: this.gaodekey
				});
				// #ifdef MP
			    	this.getLocation();
				// #endif
				
			},
	methods:{
		getLocation() {
		    const _this = this;
		    this.amapPlugin = new amap.AMapWX({
		        key: this.gaodekey
		    });
		    uni.showLoading({
		        title: '获取信息中'
		    });
		    // 成功获取位置
		    _this.amapPlugin.getRegeo({
		        success: (data) => {
		            console.log(data, '当前定位');
		            
		            _this.address =`${data[0].regeocodeData.addressComponent.city}${data[0].regeocodeData.addressComponent.district}`;
		            
		            // _this.address 可根据自己的实际情况修改
		            _this.address = `${data[0].regeocodeData.formatted_address}`;
					// 储存
					// uni.setStorageSync('province',data[0].regeocodeData.addressComponent.province)
					// uni.setStorageSync('city',data[0].regeocodeData.addressComponent.city)
					// uni.setStorageSync('district',data[0].regeocodeData.addressComponent.district)
					// 传出
		            _this.$emit("lodAddress",_this.address)
		            uni.hideLoading();
		        },
		        // 获取位置失败
		        fail: (err) => {
					console.log(err,'333');
		            uni.showToast({
		                title: "获取位置失败，请重启小程序",
		                icon: "error"
		            })
					 uni.hideLoading();
		        }
		    });
		},
	
	}
	
		}
	</script>
	
	<style lang="scss">
	
	</style>